<?php
require_once 'articleDTO.php';
require_once 'dbHelper.php';

class articleDAO extends dbHelper
{
    public function create($articleDTO)
	{
		$sql = "insert into article(title, content, postDate, level, accId)
                values('$articleDTO->title',
						'$articleDTO->content',
						'$articleDTO->postDate',
						'$articleDTO->level',
						'$articleDTO->accId')";
		parent::execQuery($sql);
		if(parent::getAffectedRows() > 0)
			return true;
		return false;
	}
    
    public function update($articleDTO)
	{
		$sql = "update article set title = $articleDTO->title',
                                  	  content = $articleDTO->content',
									  level = $articleDTO->level'";
		parent::execQuery($sql);
		if(parent::getAffectedRows() > 0)
			return true;
		return false;
	}
    
    public function delete($artId)
	{
		$sql = "delete from article where artId = '$artId'";
		parent::execQuery($sql);
		if(parent::getAffectedRows() > 0)
			return true;
		return false;
	}
    
    public function selectAll()
	{
		$listArticle = array();
		$sql = "select * from article";
		$result = parent::execQuery($sql);
		if($result && parent::getNumRows($result) > 0)
		{
			while($row = parent::fetchArray($result))
			{
				$artDTO = new articleDTO($row[artId], $row[title],
                                         $row[content], $row[postDate],
                                         $row[level], $row[accId]);
				$listArticle[count($listArticle)] = $artDTO;
			}
		}
		return $listArticle;
	}
}
?>